package us.gaaoc.framework.webapp.util;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

import java.util.TimerTask; 

import javax.faces.application.NavigationHandler;

import org.apache.log4j.Logger;

public class TimeoutTask extends TimerTask  {  
	private static final Logger LOG = Logger.getLogger(TimeoutTask.class);
	//Timer timer; 
	public void run ()   {  
		FacesContext facesContext = FacesContext.getCurrentInstance();
		NavigationHandler nh = facesContext.getApplication().getNavigationHandler();
		if (facesContext.getViewRoot() != null) {
			LOG.debug("Page is active......");
			//try {
				HttpSession httpSession = (HttpSession) facesContext.getExternalContext().getSession(false);
				httpSession.invalidate();
				nh.handleNavigation(facesContext, null, "timeOut");     
				//facesContext.getExternalContext().redirect(facesContext.getExternalContext().getRequestContextPath() + "/index.html");
             		//timer.cancel () ; //Terminate the timer thread 
			//} catch (IOException e) {
				//e.printStackTrace();
				//throw new FacesException(e);
			//}
		}
  	}  
}
    
 

